package com.hanrui.android.fragment.message.audit.issue;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.IssueDetailBean;
import com.hanrui.android.net.contract.message.audit.issue.IssueDetailContract;
import com.hanrui.android.net.presenter.message.audit.issue.IssueDetailPresenter;

import butterknife.BindView;

/**
 * 风审会、资金会审批基本信息
 *
 */

public class IssueDetailFragment extends BaseFragment<IssueDetailPresenter> implements IssueDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time_ll)
    LinearLayout timeLl;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.copies_num)
    TextView copiesNum;
    @BindView(R.id.vote_meet)
    TextView voteMeet;
    @BindView(R.id.enclosure_ll)
    LinearLayout enclosureLl;
    @BindView(R.id.enclosure)
    ImageView enclosure;
    @BindView(R.id.enclosure_num)
    TextView enclosureNum;
    @BindView(R.id.reson)
    TextView reson;

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_issue;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.issueBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static IssueDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        IssueDetailFragment fragment = new IssueDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void issueBizDetail(final IssueDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getName()+"的议案审批");
            name.setText(data.getDetail().getIssue());
            thingTitle.setText(data.getDetail().getIsProject());
            if (data.getDetail().getIsProject().equals("是")) {

                timeLl.setVisibility(View.VISIBLE);
                time.setText(data.getDetail().getMeetingApplyName());

            }

            pageNum.setText(data.getDetail().getCompanyName());
            copiesNum.setText(data.getDetail().getShowOfficeName());
            voteMeet.setText(data.getDetail().getName());
            reson.setText(data.getDetail().getRemarks());


            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                enclosureNum.setText("["+data.getFiles().size()+"]");
                enclosure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getFiles());

                    }
                });

            		}

        }

    }


}
